package samples.chapter05;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface Chapter05BookJpaDao extends JpaRepository<Chapter05Book, Integer> {
    List<Chapter05Book> getBooksByAuthorStartingWith(String author);

    List<Chapter05Book> getBooksByPriceGreaterThan(Float price);

    @Query(value = "select * from chapter05_book where id =(select max(id) from chapter05_book)", nativeQuery = true)
    Chapter05Book getMaxIdBook();

    @Query("select b from chapter05_book b where b.id > :id and b.author=:author")
    List<Chapter05Book> getBookByIdAndAuthor(@Param("author") String author, @Param("id") Integer id);

    @Query("select b from chapter05_book b where b.id < ?2 and b.name like %?1%")
    List<Chapter05Book> getBooksByIdAndName(String name, Integer id);
}
